package com.zy.db.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zy.db.annotate.Log;
import com.zy.db.utils.QueryUtils;

import java.util.List;

public interface BaseMapper<T> extends com.baomidou.mybatisplus.core.mapper.BaseMapper<T> {


    default <P extends IPage<T>> Page page(Page page, Object dto, Class<?> cla) {
        return this.selectPage(page, wrapper(dto, cla));
    }

    default Page<T> page(Integer current, Integer size, Object dto, Class<?> cla) {
        Page<T> ipage = new Page<>(current, size);
        return page(ipage, dto, cla);
    }

    default List<T> all() {
        return this.selectList(new QueryWrapper<>());
    }

    default List<T> list(Object dto, Class<?> cla) {
        return this.selectList(wrapper(dto, cla));
    }


    default T selectOne(Object dto, Class<?> cla) {
        return this.selectOne(wrapper(dto, cla));
    }

    default QueryWrapper<T> wrapper(Object dto, Class<?> cla) {
        return (QueryWrapper<T>) QueryUtils.getParam(new QueryWrapper<>(), dto, cla);
    }


}
